package li.brauch.semesterarbeit.radio.impl;


import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import li.brauch.semesterarbeit.radio.AbstractRadio;
import li.brauch.semesterarbeit.radio.model.StationTuneModel;
import li.brauch.semesterarbeit.radio.model.StationTuneResultModel;
import li.brauch.semesterarbeit.radio.model.Track;

public class Mock1RadioImpl extends AbstractRadio {
	
	private List<Track> playList = new ArrayList<Track>();
	
	private int index = 0;
	
	public Mock1RadioImpl() {
		
		Track track = new Track();
		track.setId(1001);
		track.setAlbum("Best Of");
		track.setTitle("Freunde");
		track.setArtist("Die Toten Hosen");
		track.setDuration(315000);
		
		URL resource = getURL("http://www.brauch.li/Freunde.mp3");
		
		track.setLocation(resource);
		
		resource = getURL("http://www.brauch.li/cover_dietotenhosen.png");
		track.setCover(resource);
		playList.add(track);
		
		track = new Track();
		track.setId(1001);
		track.setAlbum("Donauinsel live");
		track.setTitle("Rock me Amadeus");
		track.setArtist("Falco");
		track.setDuration(310000);
		resource = getURL("http://www.brauch.li/rock%20me%20amadeus.mp3");
		track.setLocation(resource);
		resource = getURL("http://www.brauch.li/cover_falco.png");
		track.setCover(resource);
		playList.add(track);
	}
	
	public void login() {	
		// do nothing
	}
		
	public String[] getStationTypes() {
		return new String[] {"Artist"};
	}
		
	public StationTuneResultModel tuneStation(StationTuneModel model) {
		
		StationTuneResultModel result = new StationTuneResultModel();
		result.setResults( new String[] { model.getName() });
		return result;
	}
	
	public Track getNextTrack() {
		
		index++;
		
		if (index == playList.size())
			index = 0;
		
		Track track = playList.get(index);
		
		
		
		return track;
	}
	
	public void banTrack() {
		Track track = playList.get(index);
		System.out.println("Track " + track.getTitle() + " from artist " + track.getArtist() + " baned");
	}
	
	public void loveTrack() {
		Track track = playList.get(index);
		System.out.println("Track " + track.getTitle() + " from artist " + track.getArtist() + " loved");
	}
	
	private URL getURL(String url) {
		URL result = null;
		try {
			
			result = new URL(url);
			
		
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

}
